#include"dma.h"
uint8_t flag=0;
void dma_init(void)
{
    //1.开启时钟
    RCC->AHBENR|=RCC_AHBENR_DMA1EN;

    //2.方向设置
    DMA1_Channel1->CCR&=~DMA_CCR1_DIR;  //从外设到存储器，将ROM看成外设
    DMA1_Channel1->CCR|=DMA_CCR1_MEM2MEM;  //存储器 to 存储器

    
    //3.配置传输字节大小
    DMA1_Channel1->CCR&=~DMA_CCR1_MSIZE;
    DMA1_Channel1->CCR&=~DMA_CCR1_PSIZE;
    //4.配置自增
    DMA1_Channel1->CCR|=DMA_CCR1_PINC;
    DMA1_Channel1->CCR|=DMA_CCR1_MINC;

   
    DMA1_Channel1->CCR|=DMA_CCR1_TCIE;

    NVIC_SetPriorityGrouping(3);
    NVIC_SetPriority(DMA1_Channel1_IRQn,3);
    NVIC_EnableIRQ(DMA1_Channel1_IRQn);


}

void dma_transform(uint32_t scr,uint32_t des,uint8_t leng)
{
    //1.配置传输的地址
    DMA1_Channel1->CMAR=des;
    DMA1_Channel1->CPAR=scr;

    DMA1_Channel1->CNDTR=leng;

    DMA1_Channel1->CCR|=DMA_CCR1_EN;
}

void DMA1_Channel1_IRQHandler(void)
{
    if(DMA1->ISR & DMA_ISR_TCIF1)
    {
        DMA1->IFCR|=DMA_IFCR_CTCIF1;
        flag=1;

        DMA1_Channel1->CCR&=~DMA_CCR1_EN;
    }

}




